package com.pango.system.services.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.pango.system.entity.ResourceEntity;
import com.pango.system.mapper.ResourceMapper;
import com.pango.system.mapper.RoleResourcePermissionMapper;
import com.pango.system.model.Resource;
import com.pango.system.model.RoleResourcePermission;
import com.pango.system.services.ResourceService;

@Service
public class ResourceServiceImpl implements ResourceService{
	
	@Autowired
	private ResourceMapper resourceMapper;
	
	@Autowired
	private RoleResourcePermissionMapper roleResourcePermissionMapper;
	
	@Override
	public List<Resource> getAll() {
		return resourceMapper.selectAll();
	}

	@Override
	public List<ResourceEntity> selectResourcesByUserName(String usrname) {
		return resourceMapper.selectResourcesByUserName(usrname);
	}

	@Override
	public List<ResourceEntity> selectResourcesByParentId(Long id) {
		return resourceMapper.selectResourcesByParentId(id);
	}

	@Override
	public void delRoleResourcesById(Long roleId) {
		// TODO Auto-generated method stub
		roleResourcePermissionMapper.deleteByRoleKey(roleId);
	}

	@Override
	public void addRoleResourcesBatch(List<RoleResourcePermission> records) {
		// TODO Auto-generated method stub
		roleResourcePermissionMapper.insertBatch(records);
	}

	@Override
	public List<String> selectResourceNamesByUserName(String username) {
		// TODO Auto-generated method stub
		return this.resourceMapper.selectResourceNamesByUserName(username);
	}
	

}
